// 混入代码 resize-mixins.js
import { debounce } from '@/utils/index';
const resizeChartMethod = '$__resizeChartMethod';

export default {
    data() {
        // 在组件内部将图表init的引用映射到chart属性上
        return {
            chart: null,
        };
    },
    created() {
        // 浏览器窗口监听
        window.addEventListener('resize', this[resizeChartMethod], false);
    },
    beforeDestroy() {
        window.removeEventListener('reisze', this[resizeChartMethod]);
    },
    methods: {
        // 通过lodash的防抖函数来控制resize的频率
        [resizeChartMethod]: debounce(function() {
            if (this.chart) {
                this.chart.resize();
            }
        }, 100),
    },
};